package com.googlecode.mailnet.emf.netmodel.simulation;

public class NodeStatistics {
	public double normalizedFailureProbability;
	public int dataTransmitted;
	public int dataFailed;
	public double importance;
	public int queueOverflowFaults;
	
	public static final int IMPORTANCE_AVERAGE_COUNT = 20;
	
	private final double[] importanceData = new double[IMPORTANCE_AVERAGE_COUNT];
	
	/**
	 * Calculates average importance for the last IMPORTANCE_AVERAGE_COUNT steps.
	 * @param importancePerStep
	 * @param stepNumber
	 */
	public void updateImportance(double importancePerStep, int stepNumber) {
		if (stepNumber <= IMPORTANCE_AVERAGE_COUNT) {
			importanceData[stepNumber - 1] = importancePerStep; 
		} else {
			for (int i = 1; i < IMPORTANCE_AVERAGE_COUNT; i++) 
				importanceData[i - 1] = importanceData[i];
			importanceData[IMPORTANCE_AVERAGE_COUNT - 1] = importancePerStep;
		}
		
		int count = stepNumber >= IMPORTANCE_AVERAGE_COUNT ? IMPORTANCE_AVERAGE_COUNT : stepNumber;
		this.importance = 0.0;
		for (int i = 0; i < count; ++i) this.importance += importanceData[i];
		this.importance /= count;
	}
}
